package com.lsh.payment.core.handler.impl;

import com.lsh.payment.core.handler.IRefundOrderStatusServiceHandler;
import com.lsh.payment.core.model.payenum.RefundStatus;
import com.lsh.payment.core.service.refund.AbstractRefundOrderStatusService;
import com.lsh.payment.core.service.refund.IRefundOrderStatusService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Project Name: lsh-payment
 *
 * @author peter
 * @date 18/6/2
 * 北京链商电子商务有限公司
 * Package
 * desc:
 */
@Service
public class RefundOrderStatusServiceHandler implements IRefundOrderStatusServiceHandler, InitializingBean {

    @Autowired
    private List<AbstractRefundOrderStatusService> refundOrderStatusServices;

    private Map<RefundStatus, AbstractRefundOrderStatusService> refundOrderStatusServiceMap;


    @Override
    public IRefundOrderStatusService refundOrderStatusService(RefundStatus targetStatus) {

        return refundOrderStatusServiceMap.get(targetStatus);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        refundOrderStatusServiceMap = new HashMap<>();
        for (AbstractRefundOrderStatusService as : refundOrderStatusServices) {
            refundOrderStatusServiceMap.put(as.getTargetStatus(), as);
        }

    }
}
